using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Northwind.NET.Utilities
{
    /// <summary>
    /// Keeps simple log file
    /// </summary>
    public class SimpleLogWriter
    {
        private static object _writeLogLocker = new object(); 

        /// <summary>
        /// Appends log file line
        /// </summary>
        /// <param name="message"></param>
        public static void WriteLogLine(string message)
        {
            lock (_writeLogLocker)
            {
                if (!System.IO.File.Exists(Globals.LogFullPath))
                    System.IO.File.WriteAllText(Globals.LogFullPath, "");
                message = string.Format("{0:dd/MM/yyyy HH:mm:ss} - ", DateTime.Now) + message + System.Environment.NewLine  ;
                System.IO.File.AppendAllText(Globals.LogFullPath, message);
            }
        }
        /// <summary>
        /// Resets log file by clearing all its contents
        /// </summary>
        public static void ResetLog()
        {
            lock (_writeLogLocker)
            {
                System.IO.File.WriteAllText(Globals.LogFullPath, "");
            }
        }
    }
}
